<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>课程资料</title>
	<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
	<script charset="utf-8" src='<c:url value="/js/jquery.min.js"></c:url>'></script>
	<script type="text/javascript" src='<c:url value="/js/rqfCommon/rqfCommon.js"></c:url>'></script>
	
	<link rel="stylesheet" href="../themes/default/default.css" />
	<link rel="stylesheet" href="../plugins/code/prettify.css" />
	<script charset="utf-8" src="<c:url value="/pages/kindeditor/kindeditor.js"></c:url>"></script>
	<script charset="utf-8" src="<c:url value="/pages/kindeditor/themes/default/default.css"></c:url>"></script>
	<script charset="utf-8" src="<c:url value="/pages/kindeditor/plugins/code/prettify.css"></c:url>"></script>
	<script charset="utf-8" src="<c:url value="/pages/kindeditor/lang/zh_CN.js"></c:url>"></script>
	<script charset="utf-8" src="<c:url value="/pages/kindeditor/plugins/code/prettify.js"></c:url>"></script>
	
	<script type="text/javascript"
		src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
	<script type="text/javascript"
	src='<c:url value="/js/ajaxfileupload.js"></c:url>'></script>
	<script>
	KindEditor.ready(function(K) {
        var options = {
	        filterMode : true,
	        items : [
		        'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
		        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		        'superscript', 'clearhtml', 'quickformat', '|', 'fullscreen', '/',
		        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
		        'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'pagebreak',
		        'anchor', 'link', 'unlink'
				],
				cssPath : '<c:url value="/pages/kindeditor/plugins/code/prettify.css"></c:url>',
				uploadJson :'<c:url value="/pages/kindeditor/jsp/upload_json.jsp"></c:url>',
				fileManagerJson : '<c:url value="/pages/kindeditor/jsp/file_manager_json.jsp"></c:url>',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
				},
			     afterChange: function(){ //编辑器内容发生变化后，将编辑器的内容设置到原来的textarea控件里
			            this.sync();   
			     },
			     afterBlur : function(){ //编辑器聚焦后，将编辑器的内容设置到原来的textarea控件里
			         this.sync(); 
			     }  
			};

		var editor = K.create('textarea[name="content1"]', options);
		prettyPrint();
		$("#save").click(function(){
			//alert(editor.html());
			save(editor.html());
		});
    });
	</script>
	
	<style>
		html,body{
			margin: 0;
			padding: 0;
			font-family: "微软雅黑";
		}
		li{
			list-style: none;
		}
		a{
			text-decoration: none;
		}
		.Basic_course_content{
			width: 1920px;
			width: 100%;
		}
		.Basic_course_content_content{
			width: 1280px;
			margin: 0 auto;
		}
		.Basic_course_content_content_content{
			width: 780px;
    		margin-left: 104px;
    		margin-top: 24px;
    		text-align: left;
		}
		.Basic_course_content_content_content_title{
			color: #2459aa;
			font-size: 18px;
			padding-bottom: 5px;
			border-bottom: 1px solid #2459aa;
		}
		.Basic_course_content_content_content_content{
			padding: 25px 0;
		}
		.Basic_course_content_content_content_content>ul>li{
			padding: 16px 0;
		}
		.Basic_course_content_content_content_content>ul{
			margin: 0;
			padding: 0;
			margin-bottom: 16px;
		}
		.Basic_course_content_content_content_content>ul>li>div>span{
			float: left;
			font-size: 16px;
			padding: 4px 0;
		}
		.Basic_course_content_content_content_content>ul>li>div>span>font{
			color: #ff0000;
		}
		.Basic_course_content_content_content_content>ul>li>div>input{
			width: 420px;
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select{
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>textarea{
			width: 420px;
			padding: 5px;
    		margin-top: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select>option{
			padding: 3px;
		}
		.Basic_course_baocun{
			background: #2459aa;
			color: #fff;
			font-size: 16px;
			padding: 5px 15px;
			border-radius: 3px;
			margin-left: 92px;

		}
		progress {
		    width: 100px;
		    background-color:#ededed;
		    color: #82bcff; /*IE10*/
		    border-radius: 20px;
		    position: relative;
    		left: -150px;
		}

		progress::-moz-progress-bar { background: #82bcff; border-radius: 20px;}
		progress::-webkit-progress-bar { background: #ededed; border-radius: 20px;}
		progress::-webkit-progress-value  { background: #82bcff; border-radius: 20px;}
		#upload_vedio img{
			line-height: 33px;
		    position: relative;
		    top: 6px;
		    left: -143px;
		    cursor: pointer;
		}
	</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					新增课程资料
				</div>
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 资料名称：</span>
								<input type="text" id ="source_name" >
							</div>
						</li>
						<!-- <li>
							<div>
								<span><font>*</font> 资料类型：</span>
								<select id = "class_id"> 
								      <option>请选择类型</option> 
								      <option>留学</option> 
								      <option>务工</option> 
								      <option>旅行</option> 
								      <option>商贸</option> 
								      <option>反恐</option> 
								      <option>疫情</option> 
								      <option>法律纠纷</option> 
								      <option>刑事案件</option> 
							    </select>
							</div>
						</li> -->
						<li>
							<div>
								<span><font>*</font> 资料形式：</span>
								<select id="source_type" style="width:80px;"> 
								      <option value="1">&nbsp;图文</option> 
								      <option value ="2">&nbsp;音频</option> 
								      <option value ="3">&nbsp;视频</option> 
								      <option value ="4">&nbsp;PPT</option> 
							    </select>
							</div>
						</li>
						<li>
							<div>
								<span><font></font> 资料封面：</span>
								<input id = "face" name= "picture" accept = "image/jpeg,image/jpg,image/png" type="file" style="border: 1px solid #ccc;" />
							</div>
						</li>
						<li id="edit_article">
							<div class="Basic_course_modify">
								<span><font>*</font> 编辑图文：</span>
								<textarea name ="content1" id="content1"  rows="8" cols="50" placeholder=""><%=htmlspecialchars(htmlData)%></textarea>
							</div>
						</li>
						<li id="upload_audio" style="display:none;">
							<div>
								<span><font>*</font> 上传音频：</span>
								<input id="audio" accept ="audio/mp3" name="audioName" type="file" style="border: 1px solid #ccc;">
							</div>
						</li>
						<li id="upload_vedio" style="display:none;">
							<div>
								<span><font>*</font> 上传视频：</span>
								<input id = "video" name = "videoName" accept="video/mp4" type="file" style="border: 1px solid #ccc;">
								<%-- <progress max="100" value="100"></progress>
								<img src='<c:url value="/share/img/cancel_upload.jpg"></c:url>' alt=""> --%>
							</div>
						</li>
						<li id="upload_ppt" style="display:none;">
							<div>
								<span><font>*</font> 上传PPT：</span>
								<input id = "ppt" name = "pptName" accept="application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation  " type="file" style="border: 1px solid #ccc;">
								<%-- <progress max="100" value="100"></progress>
								<img src='<c:url value="/share/img/cancel_upload.jpg"></c:url>' alt=""> --%>
							</div>
						</li>
					</ul>
					<a id="save" class="Basic_course_baocun" style="cursor:pointer;">保存</a>
					<!-- <a href="javascript:preview();" class="Basic_course_baocun">预览</a> -->
				</div>
			</div>
		</div>
	</div>
</body>
<script type = "text/javascript">
	var rootPath = '${rootPath}';
	var source_type= '${type}';
	$("#source_type").change(function(){
		source_type = $("#source_type").val();
		if (source_type == 1) {
			$("#edit_article").show();
			$("#upload_audio").hide();
			$("#upload_vedio").hide();
			$("#upload_ppt").hide();
		}else if(source_type == 3){
			$("#edit_article").hide();
			$("#upload_audio").hide();
			$("#upload_vedio").show();
			$("#upload_ppt").hide();
		}else if(source_type == 2){
			$("#edit_article").hide();
			$("#upload_audio").show();
			$("#upload_vedio").hide();
			$("#upload_ppt").hide();
		}else{
			$("#edit_article").hide();
			$("#upload_audio").hide();
			$("#upload_vedio").hide();
			$("#upload_ppt").show();
		}
	});
	
	function save(string){
		var url = rootPath + "/source/add";
		var map = new Object;
			
		map.source_name = $("#source_name").val();
		if($("#source_name").val()==""||$("#source_name").val()==null||$("#source_name").val()=="undefine"){
			top.commonTools.showTip("请输入资料名称！", 2);
			return;
		}
		map.type = $("#source_type").children('option:selected').val()
		/* map.source_name = $("#source_name").val(); */
		
		if(source_type == 1){
			if(!string){
				top.commonTools.showTip("请编辑图文资料！", 2);
				return;
			}
			map.content = string;
		}else if(source_type == 2){
			fileId = "audio";
		}else if(source_type == 3){
			fileId = "video";
		}else if(source_type == 4){
			fileId = "ppt";
		}
		var jsonData = JSON.stringify(map);
		if(source_type == 1 || $("#"+fileId+"").val()){
			var loading = mini.loading("上传中.....请勿操作！,","Loading...");
			$.ajax({
				url:url,
				method:"post",
				dataType:"json",
				data:{'data':jsonData},
				success:function(data){
					if (data) {
						if(source_type != 1){
							ajaxFileUpload(data.oid,loading);
						}else{
							top.commonTools.showTip("添加图文资料成功!", 1);
							if(parent.status1){
								 parent.status1();
							}
							if(parent.reloadList){
								 parent.reloadList();
							}
						}
					}else{
						top.commonTools.showTip(data, 2);
						mini.hideMessageBox(loading);
					}
				},
				error:function(){
					top.commonTools.showTip("上传失败！用户未登录！", 2);
					mini.hideMessageBox(loading);
				}
			});
		}else{
			top.commonTools.showTip("请选择文件!", 2);
		}
	}
	
	function preview(){
		alert("preview");
		
	}
	
	function ajaxFileUpload(id,loading) {
		var inputName,fileId;
		if(source_type == 2){
			inputName = "audioName";
			fileId = "audio";
		}else if(source_type == 3){
			inputName = "videoName";
			fileId = "video";
		}else{
			inputName = "pptName";
			fileId = "ppt";
		}
		var fileTitle = "fileTitle";
		var actionType = "course_res";
		var actionId = id;
		
		$.ajaxFileUpload({
			url : rootPath + '/attach/upload/'+inputName+'/'
				+fileTitle+'/'+actionType+'/'+actionId, //用于文件上传的服务器端请求地址
			secureuri : false, //是否需要安全协议，一般设置为false
			fileElementId : fileId, //文件上传域的ID
			dataType : 'text', //返回值类型 一般设置为json
			type : 'json',
			success : function(data, status) //服务器成功响应处理函数
			{
				var obj = successDataTransform(data);
				if(obj.isSuccess){
					coverAjaxFileUpload(id);
					top.commonTools.showTip("添加课程资料成功！", 1);
					if(parent.status1){
						 parent.status1();
					}
					if(parent.reloadList){
						 parent.reloadList();
					}
				}else{
					top.commonTools.showTip("上传失败！", 2);
				}
				mini.hideMessageBox(loading);
				
			},
			error : function(data, status, e)//服务器响应失败处理函数
			{
				//alert(e);
				mini.hideMessageBox(loading);
			}
		});
		return false;
	}
	function coverAjaxFileUpload(id) {
		var inputName = "picture";
		var fileId = "face";
		var fileTitle = "fileTitle";
		var actionType = "course_res_face";
		var actionId = id;
		$.ajaxFileUpload({
			url : rootPath + '/attach/upload/'+inputName+'/'
				+fileTitle+'/'+actionType+'/'+actionId, //用于文件上传的服务器端请求地址
			secureuri : false, //是否需要安全协议，一般设置为false
			fileElementId : fileId, //文件上传域的ID
			dataType : 'json', //返回值类型 一般设置为json
			type : 'json',
			/* data : {
				'inputName' : 'file',
				'fileTitle' : 'fileTitle',
				'actionType' : 'actionType',
				'actionId' : '1',
				'note' : '附件说明'
			}, */
			success : function(data, status) //服务器成功响应处理函数
			{
				if(data){
					//ajaxFileUpload(id,loading);
				}
			},
			error : function(data, status, e)//服务器响应失败处理函数
			{
				alert(e);
			}
		});
		return false;
	}
	
	
</script>
</html>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>